package com.turnengine.client.local.alliance.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Alliance Serializer.
 */
public class AllianceSerializer implements IAllianceSerializer {

	@Override
	public IAlliance readObject(IDataReader reader) throws IOException {

		// Read fields
		int id = reader.readInt();
		String name = reader.readString(true);
		int leaderId = reader.readInt();
		String leaderName = reader.readString(true);
		int factionId = reader.readInt();

		// Create object
		IAlliance object = new Alliance();
		object.setId(id);
		object.setName(name);
		object.setLeaderId(leaderId);
		object.setLeaderName(leaderName);
		object.setFactionId(factionId);
		return object;
	}

	public void writeObject(IDataWriter writer, IAlliance object) throws IOException {

		// Get fields
		int id = object.getId();
		String name = object.getName();
		int leaderId = object.getLeaderId();
		String leaderName = object.getLeaderName();
		int factionId = object.getFactionId();

		// Write fields
		writer.writeInt(id);
		writer.writeString(name, true);
		writer.writeInt(leaderId);
		writer.writeString(leaderName, true);
		writer.writeInt(factionId);
	}
}
